// components/myself/myself.js
const api = require('../../utils/api')
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },


  /**
   * 组件的初始数据
   */
  data: {
    on: 0,
    pay: 0,
    use: 0,
    off: 0
  },

  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
    }
  },
  pageLifetimes: {
    show: function () {
      if (!app.globalData.openid) {
        console.log("我的页面进入 getWxUserInfoCallback")
        app.getWxUserInfoCallback = (openid) => {
          console.log(openid)
          this.orderCount(openid)
        }
      } else {
        console.log("我的页面进入 getOrderInfoToShow")
        this.orderCount(app.globalData.openid)
      }
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    orderCount(openid) {
      console.log("进入orderCount方法")
      api.getOrderInfoToShow({
        openId: openid,
        orderStatus: 'on'
      }).then(res => {
        this.setData({on:res.info.length})
      })
      api.getOrderInfoToShow({
        openId: openid,
        orderStatus: 'pay'
      }).then(res => {
        this.setData({pay:res.info.length})
      })
      api.getOrderInfoToShow({
        openId: openid,
        orderStatus: 'use'
      }).then(res => {
        this.setData({use:res.info.length})
      })
      api.getOrderInfoToShow({
        openId: openid,
        orderStatus: 'off'
      }).then(res => {
        this.setData({off:res.info.length})
      })
    }
  }
})